<template>
  <div class="app-container">
    <div class="filter-container">
      <div class="filter-item">
        <span class="span">服务名称:</span>
        <el-input v-model="listQuery.serviceName" placeholder="请输入服务名称" style="width: 200px" />
      </div>
      <div class="filter-item">
        <span class="span">状态:</span>
        <el-select v-model="listQuery.status" clearable placeholder="请选择状态" style="width: 200px">
          <el-option v-for="item in dictList('is_success')" :key="'type' + item.label" :label="item.label" :value="item.value" />
        </el-select>
      </div>
      <!--      <div class="filter-item">-->
      <!--        <span>调用时间:</span>-->
      <!--        <el-input v-model="listQuery.callerDate" placeholder="请输入调用时间" style="width: 200px" />-->
      <!--      </div>-->
      <el-button v-waves class="filter-item" type="primary" icon="el-icon-search" @click="handleFilter">
        {{ $t('table.search') }}
      </el-button>
      <!--      <el-button v-waves v-permission="['marketservice:MarketServiceLog:add']" class="filter-item" style="margin-left: 10px;" type="primary" icon="el-icon-edit" @click="handleCreate">-->
      <!--        {{ $t('table.add') }}-->
      <!--      </el-button>-->
    </div>

    <el-table ref="table" :key="tableKey" v-loading="listLoading" :data="list" element-loading-text="正在加载，请稍后" border fit highlight-current-row style="width: 100%;">
      <!-- <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="table-expand">
            <el-form-item label="服务名称">
              <span>{{ props.row.marketServiceIntegration.serviceName }}</span>
            </el-form-item>
            <el-form-item label="调用者ip">
              <span>{{ props.row.callerIp }}</span>
            </el-form-item>
            <el-form-item label="调用请求头">
              <span>{{ props.row.callerHeader }}</span>
            </el-form-item>
            <el-form-item label="调用请求参数">
              <span>{{ props.row.callerParam }}</span>
            </el-form-item>
            <el-form-item label="调用报文">
              <span>{{ props.row.callerSoap }}</span>
            </el-form-item>
            <el-form-item label="调用耗时(ms)">
              <span>{{ props.row.time }}</span>
            </el-form-item>
            <el-form-item label="状态">
              <span>{{ props.row.status | dictLabel('is_success') }}</span>
            </el-form-item>
            <el-form-item label="调用时间">
              <span>{{ props.row.callerDate | parseTime('{y}-{m}-{d}') }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column> -->
      <el-table-column label="序号" align="center" type="index" width="100" />
      <el-table-column label="服务名称" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span v-if="row.marketServiceIntegration">{{ row.marketServiceIntegration.serviceName }}</span>
        </template>
      </el-table-column>
      <el-table-column label="调用耗时(ms)" align="center" min-width="150px">
        <template slot-scope="{row}">
          <span>{{ row.time }}</span>
        </template>
      </el-table-column>
      <el-table-column label="状态" min-width="150px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.status | dictLabel('is_success') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="调用时间" min-width="150px" align="center">
        <template slot-scope="{row}">
          <span>{{ row.callerDate | parseTime('{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" fixed="right" align="center" min-width="230" class-name="small-padding fixed-width">
        <template slot-scope="{row}">
          <el-button v-permission="['marketservice:MarketServiceLog:update']" type="text" size="small" icon="el-icon-edit" @click="handleUpdate(row)">
            详情
          </el-button>
          <!--          <el-button v-permission="['marketservice:MarketServiceLog:delete']" type="text" size="small" icon="el-icon-delete" class="delete-text-btn" @click="handleDelete(row,'deleted')">-->
          <!--            {{ $t('table.delete') }}-->
          <!--          </el-button>-->
        </template>
      </el-table-column>
    </el-table>
    <pagination v-show="total>0" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" :page-sizes="pageArray" @pagination="getList" />

    <market-service-log-form ref="form" @refreshList="getList" />

  </div>
</template>

<script>
import { deleteMarketServiceLog, fetchMarketServiceLogList } from '@/api/marketservicelog/marketServiceLog'
import waves from '@/directive/waves' // waves directive
import permission from '@/directive/permission/permission'
import marketServiceLogForm from './marketServiceLogForm'
import Pagination from '@/components/Pagination'

export default {
  name: 'MarketServiceLogList',
  components: { marketServiceLogForm, Pagination },
  directives: { waves, permission },
  data() {
    return {
      tableKey: 0,
      list: null,
      total: 0,
      listLoading: true,
      pageArray: this.$store.getters.pageArray,
      listQuery: {
        serviceName: undefined,
        status: undefined,
        callerDate: undefined,
        page: 1,
        limit: this.$store.getters.defaultPageSize,
      },
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      this.listLoading = true
      fetchMarketServiceLogList(this.listQuery).then((response) => {
        this.list = response.data.data
        this.total = response.data.total
        this.listLoading = false
      })
    },
    handleCreate() {
      this.$refs.form.handleCreate()
    },
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row.id)
    },
    handleDelete(row) {
      this.$confirm('确定删除该数据吗?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        deleteMarketServiceLog(row.id).then((response) => {
          if (response.data.code === 0) {
            this.getList()
            this.$message.success(response.data.msg)
          } else {
            this.$message.error(response.data.msg)
          }
        })
      })
    },
    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },
  },
}
</script>
<style lang="scss" scoped>
::v-deep(::-webkit-scrollbar) {
  display: block !important;
}
.table-expand {
  font-size: 0;
}
.table-expand label {
  width: 90px;
  color: #99a9bf;
}
.table-expand .el-form-item {
  margin-right: 0;
  margin-bottom: 0;
  width: 50%;
}
.span {
  color: #606266;
  font-weight: 700;
  font-size: 14px;
}
</style>
